package com.pinc.cpbl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Parser_Rank extends myHTMLparser {
	
	public Parser_Rank(InputStream istream) {
		super(istream, "big5");
	}

	public boolean parse(RankItem_Adapter adapter)
	{
		String retStr;
		String tmpStr;
		List<String> strlist = new ArrayList<String>();

		if ( !checkTable())
			return false;

		nextTag();
		retStr = getTagName();

		strlist.removeAll(strlist);
		while( retStr.compareTo("/table") != 0)
		{
			if ( retStr.compareTo("tr") == 0)
			{				
				if (strlist.size() > 0)
				{
					adapter.add(strlist);
				}

				strlist.removeAll(strlist);
			}
			else if( retStr.compareTo("td") == 0 || retStr.compareTo("th") == 0)
			{
				if ( retStr.compareTo("td") == 0)
					tmpStr = getContent("td");
				else
					tmpStr = getContent("th");
				
				tmpStr = tmpStr.replaceAll("<[^<>]+>", "");
				if (tmpStr.compareTo("") != 0)
				{
					strlist.add(tmpStr);
				}
			}

			nextTag();
			retStr = getTagName();
		}

		return true;
	}

}
